package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import java.util.Objects;

import com.iwhalecloud.bss.kite.cucc.service.util.ProdCateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.GeneralApnIdentifyAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;

/**
* @Description: TODO
*
* @author lyx
* @date 2020年12月19日
* @version V1.0
* @Package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler
*/
@Service
@AttrHandler(GeneralApnIdentifyAttrHandler.class)
public class GeneralApnIdentifyAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Autowired
    private OperateInstAttrService operateInstAttrService;

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        KiteAttr apnType = inst.getAttr("200003999");
        if (Objects.isNull(apnType) || KiteStringUtils.isEmpty(attr.getValue())) {
            return;
        }
        String type = apnType.getValue();
        if (KiteStringUtils.equals("100007282", type)) {
            // APN名称
            operateInstAttrService.setAttrValue(inst, "200002833", attr.getValueDesc(), data.getSceneInstId(), null);
        }
        if (!KiteStringUtils.isEmpty(attr.getValue())) {
            // 200004078
            operateInstAttrService.setAttrValue(inst, "200004078", attr.getValueDesc(), data.getSceneInstId(), null);
            // 雁飞5G智连专线连接产品 200004034
            operateInstAttrService.setAttrValue(inst, "200004034", attr.getValueDesc(), data.getSceneInstId(), null);
        }
        if (KiteStringUtils.equalsAny(inst.getSpecId(), ProdCateUtil.getMainMemberProdIdForArr(ProdCateUtil.GIFT_TYCAT1_PROD, ProdCateUtil.TY4G_PROD,
            ProdCateUtil.TY5G_PROD, ProdCateUtil.TYNB_PROD, ProdCateUtil.GIFT_ZLZXCAT_PROD))) {
            operateInstAttrService.setAttrValue(inst, "200002833", attr.getValueDesc(), data.getSceneInstId(), null);
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {
    }

}
